<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>

<body>
  <script>
    var backPack = function (m, A, V) {
      var dp = new Array(m + 1).fill(0)// 动态规划数组，初始化值为0，即没有任何物品，价值为0
      // 外层循环背包
      for (var i = 0; i <= m; i++) {
        // 内层循环物品
        for (var j = 0; j < A.length; j++) {
          if (i - A[j] >= 0) {
            dp[i] = Math.max(dp[i], dp[i - A[j]] + V[j])
          }
        }
      }
      return dp[m]// 达到背包容量时，即最大价值
    }
    console.log(backPack(25, 10, 5))
  </script>
</body>

</html>